<!doctype html>
<jsp:directive.page import="com.cn.ccp.bean.UserBean" />
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>		
<html>
<f:view>
<f:loadBundle var="messages" basename="messages"></f:loadBundle>
<head>
<base href=" <%=basePath%>"> 
<meta charset="utf-8">
<title><h:outputText value="#{messages['system_title']}" /></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]-->
    <!-- Fav and touch icons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/icon/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/icon/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/icon/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="images/icon/apple-touch-icon-57-precomposed.png">
    <link rel="shortcut icon" href="images/icon/favicon.png">
    
	<link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="js/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript" src="js/jquery.ztree.excheck-3.5.js"></script>
    
</head>
<script type="text/javascript">
<!--
var setting = {
	view: {
		selectedMulti: false
	},
	check: {
		enable: true
	},
	data: {
		simpleData: {
			enable: true
		}
	},
	callback: {
		onCheck: onCheck
	}
};

var zNodes =[
	{ id:1, pId:0, name:"随意勾选 1", open:true},
	{ id:11, pId:1, name:"随意勾选 1-1"},
	{ id:12, pId:1, name:"随意勾选  1-2", open:true},
	{ id:121, pId:12, name:"随意勾选 1-2-1", checked:true},
	{ id:122, pId:12, name:"随意勾选 1-2-2"},
	{ id:123, pId:12, name:"随意勾选 1-2-3"},
	{ id:13, pId:1, name:"随意勾选 1-3"},
	{ id:2, pId:0, name:"随意勾选 2", open:true , },
	{ id:21, pId:2, name:"随意勾选 2-1"},
	{ id:22, pId:2, name:"随意勾选 2-2", open:true ,checked:true},
	{ id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
	{ id:222, pId:22, name:"随意勾选 2-2-2"},
	{ id:223, pId:22, name:"随意勾选 2-2-3"},
	{ id:23, pId:2, name:"随意勾选 2-3", checked:true}
];

var clearFlag = false;
function onCheck(e, treeId, treeNode) {
	count();
	if (clearFlag) {
		clearCheckedOldNodes();
	}
}
function clearCheckedOldNodes() {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	nodes = zTree.getChangeCheckedNodes();
	for (var i=0, l=nodes.length; i<l; i++) {
		nodes[i].checkedOld = nodes[i].checked;
	}
}
var selectIds = "";
function count() {
	selectIds = "";
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	checkCount = zTree.getCheckedNodes(true).length,
	nocheckCount = zTree.getCheckedNodes(false).length,
	changeCount = zTree.getChangeCheckedNodes().length;
	$("#checkCount").text(checkCount);
	$("#nocheckCount").text(nocheckCount);
	$("#changeCount").text(changeCount);
	
	arr = zTree.getCheckedNodes(true) ;
	for(var i = 0 ; i < arr.length ; i ++){
		if(selectIds == '')
			selectIds = arr[i]['id'];
		else
			selectIds += ","+arr[i]['id'];
	}
	document.getElementById("form:selectRoleMenu").value = selectIds ;
}
function createTree() {
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	count();
	clearFlag = $("#last").attr("checked");
}


$(function () {
	zNodes = document.getElementById("form:hiddMenuJson").value ;
	zNodes = eval("(" + zNodes + ")");
	 createTree();
	$("#init").bind("change", createTree);
	$("#last").bind("change", createTree);
});


//-->
</script>
<body class="bg-white" style="overflow-x:hidden;">
<a id="viewDiv"></a>
	<h:form id="form">
		<h:inputHidden id="hiddMenuJson" value="#{roleAction.menuJson}"></h:inputHidden>
		<div class="row page-head">
			<h3 class="page-title">
				<i class="n-icon-selection  n-icon-black"></i><h:outputText value="#{messages['role_page_title']}"/>&nbsp;&gt;&nbsp;<b><h:outputText value="#{messages['menu_page_label_title']}" /></b>
			</h3>
		</div>
		<div style="margin-left: 20px;margin-right: 20px">
			<table border="0" align="center" cellpadding="2" cellspacing="1"
				class="table_attention">
				<tr>
					<td colspan="2" class="td_content">
						<div class="zTreeDemoBackground left">
							<ul id="treeDemo" class="ztree"></ul>
						</div>
						<div class="right" style="display: none">
							<ul class="info">
								<li class="title"><h2>1、getChangeCheckedNodes / getCheckedNodes 方法操作说明</h2>
									<ul class="list">
									<li class="highlight_red">使用 zTreeObj.getChangeCheckedNodes / getCheckedNodes 方法，详细请参见 API 文档中的相关内容</li>
									<li><p>去勾选 checkbox 比较下面的数字变化：<br/>
										<ul id="log" class="log" style="height:110px;">
											<li>当前被勾选的节点共 <span id="checkCount" class="highlight_red"></span> 个</li>
											<li>当前未被勾选的节点共 <span id="nocheckCount" class="highlight_red"></span> 个</li>
											<li>勾选状态对比规则：<input type="radio" id="init" name="stateType" class="radio first" checked /><span>与 zTree 初始化时对比</span><br/>
												<input type="radio" id="last" name="stateType" class="radio first" style="margin-left:108px;"/><span>与上一次勾选后对比</span></li>
											<li>当前被修改勾选状态的节点共 <span id="changeCount" class="highlight_red"></span> 个</li>
										</ul></p>
									</li>
									</ul>
								</li>
								<li class="title"><h2>2、setting 配置信息说明</h2>
									<ul class="list">
									<li>同 "checkbox 勾选操作" 中的说明</li>
									</ul>
								</li>
								<li class="title"><h2>3、treeNode 节点数据说明</h2>
									<ul class="list">
									<li>同 "checkbox 勾选操作" 中的说明</li>
									</ul>
								</li>
							</ul>
						</div>
					</td>
				</tr>
				<tr>
					<td class="td_button" colspan="3">
						<h:inputHidden id="selectRoleMenu" value="#{roleAction.selectRoleMenu}"></h:inputHidden>
						<h:inputHidden value="#{roleAction.rid}"></h:inputHidden>
						<a4j:commandButton value="#{messages['btn_submit']}" styleClass="btn btn-primary" ajaxSingle="true" action="#{roleAction.submitRoleMenu}"></a4j:commandButton>
						<a4j:commandButton value="#{messages['btn_cancel']}" action="main" styleClass="btn" immediate="true"></a4j:commandButton>
					</td>
				</tr>
			</table>
		</div>
	</h:form>
	<script type="text/javascript">
		$(document).ready(function() {
			//document.getElementById('viewDiv').scrollIntoView();
		});
	</script>
</body>
</f:view>
</html>
